package com.amat0urheu.dao;/*
 *@Auther:amaT0ur
 *@create:2023-11-15
 */

import com.amat0urheu.pojo.CloudPojo.IpPort;
import com.amat0urheu.pojo.CloudPojo.Scene;
import com.amat0urheu.pojo.ExperimentScene;
import com.amat0urheu.pojo.race.Race;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SceneMapper {
    @Select("SELECT *, " +
            "(SELECT COUNT(*) FROM mc_scene_image WHERE mc_scene_image.sId = mc_scene.id) AS victimNumber, " +
            "(SELECT GROUP_CONCAT(iId) FROM mc_scene_image WHERE mc_scene_image.sId = mc_scene.id) AS victims " +
            "FROM mc_scene")
    List<Scene> getScenes();




    @Select("select victim from mc_scene where Id=#{sId}")
    String getvictimByName(Integer sId);
    @Select("select ename from mc_experiment b ,mc_experiment_scene a  where b.eId=a.eId")
    List<String> getExperimentScenes();

    @Select("select a.rId,rname from mc_race_scene a, mc_race b where a.rId=b.rId ")
    List<Race> getRaceScenes();

    @Select("select sId from mc_race_scene where rId=#{rId}")
    Integer getRaceScenesByRaceId(Integer rId);
    @Insert("insert into mc_race_scene values (null,#{rId},#{sId})")
    int InsertScene(Integer rId, Integer sId);

    @Select("select sId from mc_experiment_scene where eId=#{eId}")
    Integer getExperimentToScene(Integer eId);
    @Select("select Id from mc_scene where scene=#{sceneName}")
    Integer getSceneIdBySceneName(String sceneName);
    @Insert("insert into mc_scene (scene,linkway,clientId) values (#{scene.scene},#{scene.linkway},#{scene.clientId})")
    void saveScene(@Param("scene")Scene scene);
    @Insert("insert into mc_scene_image  values (null,#{sId},#{iId})")
    void saveSceneIdAndImageId(Integer sId, Integer iId);
    @Select("select iId from mc_scene_image where sId=#{sId}")
    List<Integer> getVictimIdsBysId(Integer sId);
    @Select("select clientId  from mc_scene where Id  =#{Id}")
    Integer getclientBySid(Integer sId);
    @Select("SELECT *, " +
            "(SELECT COUNT(*) FROM mc_scene_image WHERE mc_scene_image.sId = mc_scene.id) AS victimNumber, " +
            "(SELECT GROUP_CONCAT(iId) FROM mc_scene_image WHERE mc_scene_image.sId = mc_scene.id) AS victims " +
            "FROM mc_scene where ${key} like #{value}")
    List<Scene> searchScenePage(String key, String value);
    @Update("update mc_scene set scene=#{scene.scene},linkway=#{scene.linkway},clientId=#{scene.clientId} where Id=#{scene.id}")
    int updateScene(@Param("scene")Scene scene);
    @Delete("delete from mc_scene_image where sId=#{sId}")
    void deleteImageIdofScene(Integer sId);
    @Delete("delete from mc_scene where Id=#{sId}")
    void removeScene(Integer sId);
    @Update("update mc_race_scene  set sId=#{sceneId} where rId=#{rId}")
    int updateRaceScene(Integer rId, Integer sceneId);
}
